package com.kuaimacode.kframework.api.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.kuaimacode.kframework.common.Constant;
import com.kuaimacode.kframework.mybatis.mapper.user.UserAccountDetailMapper;
import com.kuaimacode.kframework.mybatis.models.user.Address;
import com.kuaimacode.kframework.mybatis.models.user.UserAccountDetail;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 12786 on 2019/3/23.
 * @version 1.0
 */
@Service
public class UserAccountDetailService extends ServiceImpl<UserAccountDetailMapper, UserAccountDetail> {

    public PageInfo<UserAccountDetail> getUserAccountDetailPage(Long userId,int inOutType,String status,int detailType,int pageNum,int pageSize){
        PageHelper.startPage(pageNum, pageSize,true,false,null);
        QueryWrapper<UserAccountDetail> queryWrapper = new QueryWrapper();
        queryWrapper.eq("user_id",userId);
        queryWrapper.eq("status",status);
        queryWrapper.eq("in_out_type",inOutType);
        queryWrapper.eq("detail_type",detailType);
        return new PageInfo<UserAccountDetail>((List<UserAccountDetail>)baseMapper.selectList(queryWrapper));
    }


    /**
     * 查询用户账户交易明细
     * @param pageNum
     * @param pageSize
     * @param accountType
     * @param userId
     * @param queryMonth
     * @return
     */
    public PageInfo<UserAccountDetail> queryUserAccountDetailListPage(int pageNum,int pageSize,String accountType,Long userId,String queryMonth){
        PageHelper.startPage(pageNum, pageSize,true,false,null);
        QueryWrapper<UserAccountDetail> queryWrapper = new QueryWrapper();
        queryWrapper.eq("user_id",userId);
        queryWrapper.eq("status", Constant.DeleteStateEnum.NORMAL.getCode());
        queryWrapper.eq("account_type",accountType);

        if(queryMonth!=null&&!"".equals(queryMonth)){
            queryWrapper.le("date_format(create_dt,'%Y-%m')",queryMonth);
        }
        queryWrapper.orderByDesc("create_dt");

        return new PageInfo<UserAccountDetail>((List<UserAccountDetail>)baseMapper.selectList(queryWrapper));
    }
}
